﻿CREATE OR REPLACE FUNCTION "FuncMaePais_SELECT"(
	 "@OP" CHARACTER VARYING(64)
	,"@paramAux" TEXT
	,"@Id" INTEGER
	,"@FechaGrab" timestamp
	,"@UsuarioGrab" character varying(32)
	,"@Activo" boolean
	,"@CodMaePais" character varying(16)
	,"@NombreMaePais" character varying(32)
)RETURNS SETOF "MaePais"  AS $$	
    SELECT * FROM "MaePais";
$$ LANGUAGE SQL;



CREATE OR REPLACE FUNCTION fsetdatos() 
RETURNS SETOF record AS
$BODY$
 begin
 return query select * from foo;
 return;
 end;
$BODY$
 LANGUAGE plpgsql;


--select * from fsetdatos('','','');



CREATE OR REPLACE FUNCTION qa_scf(cname character varying, tname character varying)
RETURNS SETOF RECORD AS
$BODY$
BEGIN
    RETURN QUERY EXECUTE 'SELECT * from ' ||tname|| ' where ' ||cname ||' != ''AL''';
END;
$BODY$
LANGUAGE plpgsql;

SELECT *
FROM qa_scf('foo', 'bar') AS t(col1_name col1_type, ...);
/*

CREATE TABLE foo (fooid int, foosubid int, fooname text);
INSERT INTO foo VALUES (1, 1, 'Joe');
INSERT INTO foo VALUES (1, 2, 'Ed');
INSERT INTO foo VALUES (2, 1, 'Mary');


CREATE TABLE emp (
    name        text,
    salary      numeric,
    age         integer,
    cubicle     point
);

INSERT INTO emp VALUES ('Bill', 4200, 45, '(2,1)');
INSERT INTO emp VALUES ('Jhon', 4300, 45, '(2,2)');
INSERT INTO emp VALUES ('Pablo', 4400, 45, '(2,3)');
INSERT INTO emp VALUES ('Jose', 4500, 45, '(2,4)');


*/

CREATE TYPE sum_prod AS (sum int, product int);

CREATE FUNCTION select_out(x int, y int, OUT fooid int, OUT foosubid int, OUT foosubid text)
AS select * from foo
LANGUAGE SQL;

select *  from test()


CREATE OR REPLACE FUNCTION getfoo(int) RETURNS SETOF foo AS $$
    SELECT * FROM foo;-- WHERE fooid = $1;
$$ LANGUAGE 'sql';


SELECT * FROM getfoo(1)

CREATE OR REPLACE FUNCTION new_emp() RETURNS emp AS $$
/*
    SELECT 
	text 'None' AS name,
        1000.0 AS salary,
        25 AS age,
        point '(2,2)' AS cubicle;
        */
        select * from emp
$$ LANGUAGE SQL;



SELECT new_emp();
SELECT * FROM new_emp();
*/